from src.game.ability import Ability
from src.config.abilities import PROJECTILE
from src.game.entity.arrow import EntityArrow
from src.handler.sprite import SpriteHandler
import pygame

class ArrowAbility(Ability):
    
    def __init__(self, entity):
        Ability.__init__(self, PROJECTILE)
        self.entity = EntityArrow()
        self.entity.source = entity
        
    def getSprite(self):
        return SpriteHandler.get("projectile")
        
    def cast(self, client):
        x, y = client.world.player.getViewingVector()
        self.entity.x = client.world.player.x + x
        self.entity.y = client.world.player.y + y
        mx, my = pygame.mouse.get_pos()
        mx = mx / 64. + client.window.viewport.x
        my = my / 64. + client.window.viewport.y
        self.entity.setTarget(mx, my)
        client.world.spawnEntity(self.entity)